package com.code.bolg.aop;

import com.code.bolg.exception.BolgExcetion;
import com.code.bolg.utils.ApiReturnUtil;
import com.code.bolg.vo.ResultVo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AppAop {

//    @Pointcut("execution( * com.code.bolg.controller.*.*(..))")
    public void pointCutAt() {
    }

//    @Around("pointCutAt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        ResultVo msg;
        try {
            msg = ApiReturnUtil.success(pjp.proceed());
        } catch (BolgExcetion e) {
            e.printStackTrace();
            msg = ApiReturnUtil.custonFail(e);
        } catch (Exception e) {
            e.printStackTrace();
            msg=ApiReturnUtil.fail();
        }
        return msg;
    }
}
